﻿namespace BankExercise
{
    using System;

    internal class MortgageAcc : Account, IDepositable
    {
        public override void Deposit(decimal sumToDeposit)
        {
            base.Deposit(sumToDeposit);
        }

        internal override decimal CalculateInterest(int periodInMonths)
        {
            if (this.InterestRatePerMonth == 0)
            {
                throw new InvalidOperationException("No way you do that: calculate interest amount before you have set an intereset index.");
            }
            else
            {
                if ((this.AccCustomer is CompanyCus) == true)
                {
                    if (periodInMonths <= 12)
                    {
                        return this.InterestRatePerMonth * (periodInMonths / 2);
                    }
                    else
                    {
                        return this.InterestRatePerMonth * periodInMonths;
                    }
                }
                else if ((this.AccCustomer is IndividualCus) == true)
                {
                    if (periodInMonths <= 6)
                    {
                        return 0;
                    }
                    else
                    {
                        return this.InterestRatePerMonth * periodInMonths;
                    }
                }
                else
                {
                    throw new ArgumentOutOfRangeException("What a mess");
                }
            }
        }
    }
}